﻿using System;
using System.Collections.Generic;
using System.Text;

namespace WeatherSystem.Application.Model
{
    class UserModel : BaseModel
    {
        protected override string TableName => "user";
        public bool Exists(string username)
        {
            var result = Select("name", username);
            return result.Count != 0;
        }
        public bool Bind(string user, string device)
        {
            var id = InsertGetID(new Dictionary<string, object>
            {
                { "name", user },
                { "device", device }
            });
            return id != 0L;
        }
        public void Rebind(string user, string device)
        {
            Update("name", user, new Dictionary<string, object>
            {
                { "name", user },
                { "device", device }
            });
        }
    }

    class DeviceeModel : BaseModel
    {
        protected override string TableName => "device";
        public bool Exists(string sn, ref string name)
        {
            var result = Select("sn", sn);
            if(result.Count!= 0)
            {
                name = result[0]["name"].ToString();
            }
            return result.Count != 0;
        }
    }

    class DataModel : BaseModel
    {
        protected override string TableName => "data";
    }
}
